<?php
/**
 * Created by PhpStorm.
 * User: chenxiang
 * Date: 2017/4/30
 * Time: 12:58
 */

namespace App\Http\Controllers\Home;


use App\Model\Json;
use App\Model\Permission;
use Illuminate\Http\Request;

class PermissionController extends CommonController
{

    public function index(){
//        $all = Permission::get()->toArray();
//        foreach($all as &$val){
//            unset($val['deleted_at']);
//            unset($val['updated_at']);
//            unset($val['created_at']);
//        }
//        var_export($all);
//        exit;
        $data = Permission::paginate(15);
        return view('Home.Permission.index',compact('data'));
    }


    public function edit(Request $request){
        $data = $request->only('id','name');
        $permission = Permission::find($data['id']);
        if(!$permission){
            return Json::error('权限id有误');
        }
        $data = $permission->validate($data);
        if(!$data['status']){
            return $data;
        }
        $permission->name = $data['data']['name'];
//        $permission->admin_id = auth()->user()->id;
        if($permission->save()){
            return Json::success('修改成功');
        }else{
            return Json::error('修改失败');
        }
    }



    public function All(){
        return Json::success(Permission::get());
    }


}